package com.imooc.coupon.constant;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * @Date 2021/11/2 19:08
 * @Author wangshbv
 * @Description 商品类型枚举
 */
@AllArgsConstructor
@Getter
public enum GoodsType {

    WENYU("文娱",1),
    SHENGXIAN("生鲜",2),
    JIAJU("家具",3),
    OTHERS("其他",4),
    ALL("全品类",5);

    private String description;

    private Integer code;

    public static GoodsType of(Integer code) {
        Objects.requireNonNull(code);
        return Stream.of(values())
                .filter(bean -> bean.getCode().equals(code))
                .findAny().orElseThrow(() -> new IllegalArgumentException(code + " is not Exitsts!"));
    }
}
